const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = env => {
  return {

    mode: env.production ? 'production' : 'development',

    entry: './src/main.ts',
    output: {
      path: path.resolve(__dirname, './dist'),
      publicPath: '/dist',
      filename: 'dist.js'
    },
    devServer: {
      port: 8001,
      proxy: {
        "/api": {
          target: "http://localhost:8000/public",
          pathRewrite: {
            "^/api": ""
          },
          secure: false
        }
      }
    },
    resolve: {
      extensions: ['.ts', '.tsx', '.json', '.js']
    },

    module: {
      rules: [{
        test: /\.tsx?$/,
        loader: "ts-loader"
      }]
    },
    optimization: {
      minimize: true,
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            output: {
              comments: false,
            },
          },
          extractComments: false,
        }),
      ],
    },
  };
}